package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "订单接口")
@RequestMapping("/user/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 用户下单
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        OrderSubmitVO vo = ordersService.submit(ordersSubmitDTO);
        return Result.success(vo);
    }

    /**
     * 订单支付 -虚假的支付成功
     * @param ordersPaymentDTO
     * @return
     * @throws Exception
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO)throws Exception{
        ordersService.update(ordersPaymentDTO);
        return Result.success();
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @ApiOperation("查询订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result<Orders> findOrderDetailByOrderId(@PathVariable Long id){
        return Result.success(ordersService.findOrderDetailByOrderId(id));
    }

    /**
     * 查询历史订单
     * @return
     */
    @ApiOperation("查询历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> findHistoryOrdersPage(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult historyOrdersPage = ordersService.findHistoryOrdersPage(ordersPageQueryDTO);
        log.info("历史订单：{}", historyOrdersPage);
        return Result.success(historyOrdersPage);
    }



   /*
   * 真实的支付成功
   *  *//**
     * 订单支付
     * @return
     *//*
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO)throws Exception{
        OrderPaymentVO vo = ordersService.payment(ordersPaymentDTO);
        return Result.success(vo);
    }
    *//**
     * 支付成功回调方法
     * https://6ffcf133.r2.cpolar.cn/user/order/paySuccess
     * @return
     *//*
    @RequestMapping("/paySuccess")
    public Result paySuccess(){

        return Result.success();
    }*/


}
